<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=9; IE=8; IE=7; IE=EDGE">
    <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7"/>
    <title>乐优商城--我的订单</title>
    <link rel="icon" href="assets/img/favicon.ico">

    <link rel="stylesheet" type="text/css" href="css/webbase.css"/>
    <link rel="stylesheet" type="text/css" href="css/pages-seckillOrder.css"/>
</head>

<body>

<!-- 头部栏位 -->
<!--页面顶部，由js动态加载-->
<script type="text/javascript" src="plugins/jquery/jquery.min.js"></script>

<script type="text/javascript" src="js/plugins/jquery.easing/jquery.easing.min.js"></script>
<script type="text/javascript" src="js/plugins/sui/sui.min.js"></script>
<script type="text/javascript" src="js/plugins/jquery-placeholder/jquery.placeholder.min.js"></script>
<script type="text/javascript" src="js/widget/nav.js"></script>
<script src="./js/qrcode.min.js"></script>
</body>
<!--header-->
<div id="account">
    <div id="nav-bottom"></div>
    <ly-top></ly-top>
    <div class="py-container">
        <div class="yui3-g home">
            <!--左侧列表-->
            <div class="yui3-u-1-6 list">

                <div class="person-info">
                    <div class="person-photo"><img src="img/_/photo.png" alt=""></div>
                    <div class="person-account">
                        <span class="name">{{user.username}}</span>
                        <span class="safe"><a href="#" @click="logout">退出登录 </a></span>
                    </div>
                    <div class="clearfix"></div>
                </div>
                <div class="list-items">
                    <dl>
                        <dt><i>·</i> 订单中心</dt>
                        <dd><a href="javascript:void(0)" @click="query.status=0" :class="{'list-active':query.status===0}">我的订单</a></dd>
                        <dd><a href="javascript:void(0)" @click="query.status=1" :class="{'list-active':query.status===1}">待付款</a></dd>
                        <dd><a href="javascript:void(0)" @click="query.status=2" :class="{'list-active':query.status===2}">待发货</a></dd>
                        <dd><a href="javascript:void(0)" @click="query.status=3" :class="{'list-active':query.status===3}">待收货</a></dd>
                        <dd><a href="javascript:void(0)" @click="query.status=4" :class="{'list-active':query.status===4}">待评价</a></dd>
                    </dl>
                    <dl>
                        <dt><i>·</i> 我的中心</dt>
                        <dd><a href="home-person-collect.html">我的收藏</a></dd>
                        <dd><a href="home-person-footmark.html">我的足迹</a></dd>
                    </dl>
                    <dl>
                        <dt><i>·</i> 物流消息</dt>
                    </dl>
                    <dl>
                        <dt><i>·</i> 设置</dt>
                        <dd><a href="home-setting-info.html">个人信息</a></dd>
                        <dd><a href="home-setting-address.html">地址管理</a></dd>
                        <dd><a href="home-setting-safe.html">安全管理</a></dd>
                    </dl>
                </div>
            </div>
            <!--右侧主内容-->
            <div class="yui3-u-5-6 order-pay">
                <div class="body">
                    <div class="table-title">
                        <table class="sui-table  order-table">
                            <tr>
                                <thead>
                                <th width="35%">宝贝</th>
                                <th width="5%">单价</th>
                                <th width="5%">数量</th>
                                <th width="8%">商品操作</th>
                                <th width="10%">实付款</th>
                                <th width="10%">交易状态</th>
                                <th width="10%">交易操作</th>
                                </thead>
                            </tr>
                        </table>
                    </div>




                    <!--搜索框 sui-btn-->
                    <div class="search">
                        <form action="" class="sui-form form-inline">
                            <!--searchAutoComplete-->
                            <div class="input-append">
                                <input type="text" id="autocomplete"  v-model="query.key"
                                       class="input-error " style="color: #00c853;border-color: #00c853"/>
                                <button @click="loadOrder" class=" btn-xlarge btn-danger"     type="button" >订单搜索</button>
                            </div>
                        </form>
                    </div>





                   <!-- <div class="order-detail">
                        <div class="orders">
                            <div class="choose-order">
                                <div class="sui-pagination pagination-large top-pages">
                                    <ul>
                                        <li class="prev disabled"><a href="#">上一页</a></li>

                                        <li class="next"><a href="#">下一页</a></li>
                                    </ul>
                                </div>
                            </div>-->

                            <!--order1-->
                            <div v-for="(o, i) in orders" :key="i">
                            <div class="choose-title">
                                <label data-toggle="checkbox" class="checkbox-pretty ">
                                    <input type="checkbox" checked="checked" />
                                    <span>{{formatDate(o.createTime)}}　订单编号：{{o.orderId}} <a>联系客服</a></span>
                                </label>
                                <a class="sui-btn btn-info share-btn">分享</a>
                            </div>
                            <table class="sui-table table-bordered order-datatable">
                                <tbody>
                                <tr v-for="(d,j) in o.orderDetails" :key="j">
                                    <td width="35%">
                                        <div class="typographic"><img width="70px" height="70px" :src="d.image"/>
                                            <a href="#" class="block-text">包邮 {{d.title}}</a>
                                            <span class="guige" v-for="(v,k) in JSON.parse(d.spec)" :key="k">{{k+':'+ v}}</span>
                                        </div>
                                    </td>
                                    <td width="5%" class="center">
                                        <ul class="unstyled">
                                            <li>¥{{formatPrice(d.price)}}</li>
                                        </ul>
                                    </td>
                                    <td width="5%" class="center">{{d.num}}</td>
                                    <td width="8%" class="center" :rowspan="o.orderDetails.length" v-if="j === 0">

                                        <ul class="unstyled" v-if="o.status === 3">
                                            <li>已发货</li>
                                            <li><a @click="backpay(o.orderId,o.actualFee)">退货/退款</a></li>
                                        </ul>
                                    </td>
                                    <td width="10%" class="center" :rowspan="o.orderDetails.length" v-if="j === 0">
                                        <ul class="unstyled">
                                            <li>¥{{formatPrice(getTotalPrice(o))}}</li>
                                            <li>（含运费：￥0.00）</li>
                                        </ul>
                                    </td>
                                    <td width="10%" class="center" :rowspan="o.orderDetails.length" v-if="j === 0">
                                        <ul class="unstyled">
                                            <li v-if="o.status === 1">等待买家付款</li>
                                            <li v-if="o.status === 2">已付款</li>
                                            <li v-if="o.status === 3">已发货</li>
                                            <li><a class="btn"  @click="findDetail(o.orderId)">订单详情 </a></li>
                                        </ul>
                                    </td>
                                    <td width="10%" class="center" :rowspan="o.orderDetails.length" v-if="j === 0">
                                        <ul class="unstyled">

                                            <li v-if="o.status === 1"><a  class=""><span :id="o.orderId">订单关闭:</span></a></li>
                                            <li v-if="o.status === 1"><a  class="sui-btn btn-info" @click="paygoods(o.orderId)">立即付款</a></li>
                                            <li v-if="o.status === 2"><a  class="sui-btn btn-info" @click="sendgoods(o.orderId)">提醒发货</a></li>
                                            <li v-if="o.status === 3"><a  class="sui-btn btn-info" @click="confirmgoods(o.orderId)">确认收货</a></li>
                                            <li v-if="o.status === 4"><a href="comment.html?id=1304372936920043522" class="sui-btn btn-info">评价</a></li>
                                            <li v-if="o.status === 3"><a  class=""><span :id="o.orderId+1"></span>自动确认</a></li>
                                            <li><a href="javascript:void(0)">取消订单</a></li>
                                        </ul>
                                    </td>
                                </tr>
                                </tbody>
                            </table>
                            </div>
                        </div>






                        <div class="choose-order">

                            <div class="sui-pagination pagination-large top-pages">
                                <ul>
                                    <li :class="{prev:true,disabled:query.page === 1}">
                                        <a href="#" @click.prevent="prePage">«上一页</a>
                                    </li>
                                    <li :class="{active: index(i) === query.page}" v-for="i in Math.min(5,totalPage)" :key="i">
                                        <a href="#" @click.prevent="query.page=index(i)">{{index(i)}}</a>
                                    </li>
                                    <li class="dotted" v-show="totalPage > 5" ><span>...</span></li>

                                    <li :class="{next:true,disabled:query.page === totalPage}">
                                        <a href="#" @click.prevent="nextPage">下一页»</a>
                                    </li>
                                </ul>
                                <div><span>共{{totalPage}}页&nbsp;</span><span>
                                            到
                                            <input type="text" class="page-num" v-model="toPageNum">
                                            页 <button class="page-confirm" @click="toPage">确定</button>

                                   <!-- onclick="alert(1)-->

                                </span>
                                </div>
                            </div>
                        </div>







                        <div class="clearfix"></div>
                    </div>

                    <div class="like-title">
                        <div class="mt">
                            <span class="fl"><strong>热卖单品</strong></span>
                        </div>
                    </div>
                    <div class="like-list">
                        <ul class="yui3-g">
                            <li class="yui3-u-1-4">
                                <div class="list-wrap">
                                    <div class="p-img">
                                        <img src="img/_/itemlike01.png"/>
                                    </div>
                                    <div class="attr">
                                        <em>DELL戴尔Ins 15MR-7528SS 15英寸 银色 笔记本</em>
                                    </div>
                                    <div class="price">
                                        <strong>
                                            <em>¥</em>
                                            <i>3699.00</i>
                                        </strong>
                                    </div>
                                    <div class="commit">
                                        <i class="command">已有6人评价</i>
                                    </div>
                                </div>
                            </li>
                            <li class="yui3-u-1-4">
                                <div class="list-wrap">
                                    <div class="p-img">
                                        <img src="img/_/itemlike02.png"/>
                                    </div>
                                    <div class="attr">
                                        <em>Apple苹果iPhone 6s/6s Plus 16G 64G 128G</em>
                                    </div>
                                    <div class="price">
                                        <strong>
                                            <em>¥</em>
                                            <i>4388.00</i>
                                        </strong>
                                    </div>
                                    <div class="commit">
                                        <i class="command">已有700人评价</i>
                                    </div>
                                </div>
                            </li>
                            <li class="yui3-u-1-4">
                                <div class="list-wrap">
                                    <div class="p-img">
                                        <img src="img/_/itemlike03.png"/>
                                    </div>
                                    <div class="attr">
                                        <em>DELL戴尔Ins 15MR-7528SS 15英寸 银色 笔记本</em>
                                    </div>
                                    <div class="price">
                                        <strong>
                                            <em>¥</em>
                                            <i>4088.00</i>
                                        </strong>
                                    </div>
                                    <div class="commit">
                                        <i class="command">已有700人评价</i>
                                    </div>
                                </div>
                            </li>
                            <li class="yui3-u-1-4">
                                <div class="list-wrap">
                                    <div class="p-img">
                                        <img src="img/_/itemlike04.png"/>
                                    </div>
                                    <div class="attr">
                                        <em>DELL戴尔Ins 15MR-7528SS 15英寸 银色 笔记本</em>
                                    </div>
                                    <div class="price">
                                        <strong>
                                            <em>¥</em>
                                            <i>4088.00</i>
                                        </strong>
                                    </div>
                                    <div class="commit">
                                        <i class="command">已有700人评价</i>
                                    </div>
                                </div>
                            </li>

                        </ul>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="clearfix footer"></div>

    <foot></foot>

    <side-panel></side-panel>
</div>

<!--页面顶部，由js动态加载-->
<script src="./js/vue/vue.js"></script>
<script src="./js/axios.min.js"></script>
<script src="./js/common.js"></script>
<script src="./js/pages/shortcut.js"></script>
<script src="./js/pages/top.js"></script>
<script src="./js/pages/copyright.js"></script>
<script src="./js/pages/foot.js"></script>
<script src="./js/pages/side-panel.js"></script>
<script src="./js/plugins/jquery/jquery.cookie.js"></script>
<script type="text/javascript">
    let outArr;
    var vm = new Vue({
        el: "#account",
        data: {
            total: 0,// 总条数
            totalPage: 0, // 总页数
            toPageNum: 1,// 要跳到第几页
            user: {},
            orders:[],
            query:{
                status:0,
                page:1,
                rows:2,
                key: null
            },

        },
        created() {
            // 查询订单信息
            this.loadOrder();

        },


        watch: {
            "query.key"(val, oldVal) {
                if (!oldVal) {
                    return;
                }
                // 搜索
                this.loadOrder();


            },
            "query.page"(val, oldVal) {
                if (!oldVal) {
                    return;
                }
                let {key, ...obj} = this.query;
                location.hash = "#" + ly.stringify(obj);
                // 搜索
                this.loadOrder();

            },
            "query.status"(val, oldVal) {

                let {status, ...obj} = this.query;
                location.hash = "#" + ly.stringify(obj);
                // 搜索
                this.query.page=1;
                this.loadOrder();

            }
        },


        methods: {

            toPage() {

                let aa=Math.max(Math.min(this.totalPage, this.toPageNum), 1)

                this.query.page = Math.max(Math.min(100, this.totalPage, this.toPageNum), 1);

            },
            nextPage() {
                if (this.query.page < this.totalPage) this.query.page++;
            },
            prePage() {
                if (this.query.page > 1) this.query.page--;
            },
            index(i) {
                if (this.query.page <= 3 || this.totalPage <= 5) {
                    // 当前页小于3，则页码就是从 i 开始
                    return i;
                } else if (this.query.page <= this.totalPage - 2) {
                    // 大于3，则从page-2开始，然后逐个加1
                    return this.query.page - 3 + i;
                } else {
                    return this.totalPage - 5 + i;
                }
            },
            backpay(id,price) {
               console.log(price)
                ly.http.get("/trade/pay/back?orderid="+id+"&price="+price)
                    .then(resp => {
                        console.log(resp.data);
                       if (resp.data.returnCode==="SUCCESS"){
                           window.location = "paybacksuccess.html" ;
                       }
                    })
                    .catch(e => console.log(e))
            },
            paygoods(id){
                window.location = "pay.html?id=" + id;
            },
            sendgoods(id){
                /*ly.http.get("/trade/order/RemindDelivery/"+id)
                    .then(resp => {

                    })
                    .catch(e => console.log(e))*/
                window.location = "http://api.leyou.com/trade/order/RemindDelivery/"+id;
            },
            confirmgoods(id){
                window.location = "http://api.leyou.com/trade/order/confirmreceipt/"+id;
                this.loadOrder();
            },
            findDetail(id){
                window.location = "home-orderDetail.html?id=" + id;
            },
            logout(){

            },
            gotoLogin() {
                window.location = "login.html?returnUrl=" + window.location;
            },
            loadOrder(){
                // 查询订单信息
                let arr = [{
                    orderId: 10010123410,
                    totalFee: 549800,
                    actualFee: 549800,
                    status: this.query.status || 1,
                    createTime: 15324812456,
                    orderDetails: [

                    ]
                }];


                ly.http.post("/trade/order/findAllOrder", this.query).then(resp => {
                         console.log(resp.data);
                        // 分页数据
                        this.total = resp.data.total;
                        // 计算总页数
                        this.totalPage = resp.data.totalPage;
                        // 订单
                        //this.orders = resp.data.items;
                        this.orders = resp.data.items;
                        //this.timeab=resp.data.items.createTime;
                        outArr=this.orders;
                    })
                    .catch(e => console.log(e))

               // this.orders = arr;


            },
            formatDate:ly.formatDate,
            formatPrice: ly.formatPrice,
            getTotalPrice(order){
                return order.actualFee;
            }
        }
    });


//待付款时间
    let timmer=setInterval(changeDate,1000);
    function changeDate() {
        for (let i in outArr) {
            console.log("================")
            console.log(new Date().getTime());
            console.log(outArr[i].createTime);
            let use = new Date().getTime() - outArr[i].createTime;//已经用过的时间
            console.log(use)
            let timeM = 30 * 60 * 1000 - use;//还剩的时间
             console.log(timeM);

            let min = Math.floor(timeM / 60 / 1000);
            let second = Math.floor((timeM - min * 60 * 1000) / 1000);
            let time = min + "分" + second + "秒";
            console.log(time);
            let id=outArr[i].orderId;
            if(timeM<=0){
                clearInterval(timmer);
                document.getElementById(id).innerHTML="订单已经关闭";
            }
            document.getElementById(id).innerHTML=time;
            console.log(id);

        }
    }



//确认收货时间
    let timmer1=setInterval(changeDate1,1000);
    function changeDate1() {
        for (let i in outArr) {
            console.log("…………………………………………………………")
            console.log(new Date().getTime());
            console.log(outArr[i].endTime);
            let use = new Date().getTime() - outArr[i].endTime;//已经用过的时间
            console.log(use)
            let timeM = 7 * 24 * 60 * 60 * 1000 - use;//还剩的时间
            console.log(timeM);

            //let min = Math.floor(timeM / 60 / 1000);
            //let second = Math.floor((timeM - min * 60 * 1000) / 1000);
            //let time = min + "分" + second + "秒";


            let day=Math.floor(timeM  /24 / 60 / 60 / 1000);
            let hour = Math.floor((timeM  - day * 24 * 60 * 60 * 1000) / 60 / 60/ 1000);
            let min = Math.floor((timeM  - day * 24 * 60 * 60 * 1000- hour * 60 * 60 * 1000) / 60 / 1000);
            let second = Math.floor((timeM  - day * 24 * 60 * 60 * 1000- hour * 60 * 60 * 1000 - min * 60 * 1000) / 1000);
            let time = day + "天" + hour + "时" + min + "分" + second + "秒";
            console.log(time);
            let id=outArr[i].orderId+1;
            document.getElementById(id).innerHTML=time;
            console.log(id);
            if(timeM===0){
                clearInterval(timmer1);
                document.getElementById(id).innerHTML="订单已经关闭";
            }
        }
    }


</script>
<script type="text/javascript">
    $(function () {
        $("#service").hover(function () {
            $(".service").show();
        }, function () {
            $(".service").hide();
        });
        $("#shopcar").hover(function () {
            $("#shopcarlist").show();
        }, function () {
            $("#shopcarlist").hide();
        });

    })
</script>
</html>